<g:javascript src="jquery/ajaxupload.js" />

<script type="text/javascript">/*<![CDATA[*/
	$(document).ready(function(){
		/* Example 1 */
		var button = $('#upload_but'), interval;
		
		new AjaxUpload(button, {
			action: '/fileUploader/process', 
			name: 'file',
            responseType: 'json',
            data : {
				'upload' : "schoollogo",
				'pid' : "1",
				'successAction' : "upload",
				'successController' : "schoolInfoAjax",
				'errorAction' : "upload",
				'errorController' : "schoolInfoAjax"
			}, 

			onSubmit : function(file, ext){
				// change button text, when user selects file			
				button.text('Uploading');
								
				// If you want to allow uploading only 1 file at time,
				// you can disable upload button
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = button.text();
					if (text.length < 13){
						button.text(text + '.');					
					} else {
						button.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				button.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload button
				this.enable();

                //alert(file);
                console.log(response.success +"||" + response.message);
                if (response.success)
                {	// add file to the list
				    $('.files').html('<img src="/download/index/'+response.message+'"/>');
                    $('#schoolInfoLogo').val(response.message);
                }else{
                    $(".files").html('<div class="errors">' + response.message + '</div');
                    $('#schoolInfoLogo').val('');
                }
			}
		});

	});

    
//        String name = ''
//    String adds = ''
//    String level = '' //等级
//    String tel = ''
//    String post = '' //邮编
//    String headmaster = '' //校长
  //验证部分
 $("#schoolInfoCreate").validate({
            rules: {
                name : {
                    maxlength : 150
                },
                adds : {
                    maxlength : 250
                },
                level : {
                    maxlength : 250
                },
                tel : {
                    maxlength : 250
                },
                post : {
					maxlength : 250
                },
                headmaster : {
                    maxlength : 250
                }
            },
            messages: {
                name : {
                    maxlength : "学校名称长度不能大于150字！"
                },
                adds : {
                    maxlength : "学校地址长度不能大于250字！"
                },
                level : {
                    maxlength : "学校类别长度不能大于250字！"
                },
                tel : {
                    maxlength : "学校电话长度不能大于250字！"
                },
				post : {
                    maxlength : "学校邮编长度不能大于250字！"
                headmaster : {
                    maxlength : "校长长度不能大于250字！"
                }
            }
        });
    /*]]>*/</script>